package com.yilin.medical.fragment;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.yilin.medical.R;
import com.yilin.medical.activity.GuoJiGuoNeiZhuanZhenActivity;
import com.yilin.medical.activity.GuoJiGuoNeiZhuanZhenActivity2;
import com.yilin.medical.activity.ShiPinHuiZhenDetailsActivity;
import com.yilin.medical.adapter.GuoJiGuoNeiZhuanZhenAdapter;
import com.yilin.medical.adapter.ShiPinHuiZhenAdapter;
import com.yilin.medical.model.GuoJiGuoNeiZhuanZhenBean;
import com.yilin.medical.model.ShiPinHuiZhenBean;
/**
 * 肿瘤
 * @author lijianqun
 *
 */
public class GuoJiGuoNeiZhuanZhenFragment extends Fragment implements OnItemClickListener,OnItemSelectedListener, OnClickListener {
	private Context context;
	private View mView;
	private ListView mListViewZhongLiu;
	private List<GuoJiGuoNeiZhuanZhenBean> mList;
	private Spinner mSpinnerXueKe, mSpinnerGuoJi,mSpinnerYiYuan,mSpinnerYiSheng;
	private List<String> mListXueKe = new ArrayList<String>();
	private List<String> mListGuoJi = new ArrayList<String>();
	private List<String> mListYiYuan = new ArrayList<String>();
	private List<String> mListYiSheng = new ArrayList<String>();
	private ArrayAdapter<String> mAdapterXueKe ;
	private ArrayAdapter<String> mAdapterGuoJi ;
	private ArrayAdapter<String> mAdapterYiYuan ;
	private ArrayAdapter<String> mAdapterYiSheng ;
	private TextView mTextViewSearch;
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		context = activity;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = View.inflate(context, R.layout.fragment_guojiguoneihuizhen, null);
		initview();
		registerLstener();
		initData();
		fillData();
		return mView;
	}

	private void registerLstener() {
		mListViewZhongLiu.setOnItemClickListener(this);
		mTextViewSearch.setOnClickListener(this);
	}

	private void initData() {
		if (mListXueKe.size()>0) {
			mListXueKe.clear();
		}
		mListXueKe.add("儿科");
		mListXueKe.add("眼科");
		
		if (mListGuoJi.size()>0) {
			mListGuoJi.clear();
		}
		mListGuoJi.add("国际");
		mListGuoJi.add("国内");
		
		if (mListYiYuan.size()>0) {
			mListYiYuan.clear();
		}
		mListYiYuan.add("人民医院");
		mListYiYuan.add("铁路医院");
		
		if (mListYiSheng.size()>0) {
			mListYiSheng.clear();
		}
		mListYiSheng.add("张医生");
		mListYiSheng.add("王医生");
		
		mAdapterXueKe = new ArrayAdapter<String>(context,
				android.R.layout.simple_spinner_item, mListXueKe);
		mAdapterGuoJi = new ArrayAdapter<String>(context,
				android.R.layout.simple_spinner_item, mListGuoJi);
		mAdapterYiSheng = new ArrayAdapter<String>(context,
				android.R.layout.simple_spinner_item, mListYiSheng);
		mAdapterYiYuan = new ArrayAdapter<String>(context,
				android.R.layout.simple_spinner_item, mListYiYuan);
//		 第三步：为适配器设置下拉列表下拉时的菜单样式。
		mAdapterXueKe.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mAdapterGuoJi.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mAdapterYiSheng.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mAdapterYiYuan.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// 第四步：将适配器添加到下拉列表上
//		mySpinner.setAdapter(adapter);
		mSpinnerXueKe.setAdapter(mAdapterXueKe);
		mSpinnerGuoJi.setAdapter(mAdapterGuoJi);
		mSpinnerYiSheng.setAdapter(mAdapterYiSheng);
		mSpinnerYiYuan.setAdapter(mAdapterYiYuan);
	}

	private void fillData() {
		mList = new ArrayList<GuoJiGuoNeiZhuanZhenBean>();
		for (int i = 0; i < 10; i++) {
			mList.add(new GuoJiGuoNeiZhuanZhenBean());
		}
		GuoJiGuoNeiZhuanZhenAdapter mAdapter = new GuoJiGuoNeiZhuanZhenAdapter(context, mList);
		mListViewZhongLiu.setAdapter(mAdapter);
	}

	private void initview() {
		mListViewZhongLiu = (ListView) mView.findViewById(R.id.lv_zhongliu);
		mSpinnerXueKe = (Spinner) mView.findViewById(R.id.Spinner_xueke);
		mSpinnerGuoJi = (Spinner) mView.findViewById(R.id.Spinner_guoji);
		mSpinnerYiYuan = (Spinner) mView.findViewById(R.id.Spinner_yiyuan);
		mSpinnerYiSheng = (Spinner) mView.findViewById(R.id.Spinner_yisheng);
		mTextViewSearch = (TextView) mView.findViewById(R.id.tv_search);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		//跳到视频会诊详情
		Intent intent = new Intent(context,ShiPinHuiZhenDetailsActivity.class);
		startActivity(intent);
		
	}

	@Override
	public void onItemSelected(AdapterView<?> parent, View selectview,
			int positon, long arg3) {
		selectview.setVisibility(View.VISIBLE);
	}

	@Override
	public void onNothingSelected(AdapterView<?> parent) {
		parent.setVisibility(View.VISIBLE);
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.tv_search:
			//TODO 跳转到国际国内世纪别表//坑爹的设计
			intent = new Intent(context, GuoJiGuoNeiZhuanZhenActivity2.class);
			startActivity(intent);
			break;

		default:
			break;
		}
		
	}
}
